package com.zimmur.common;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

@Component
public class SpringBeanFactory  implements ApplicationContextAware{
	private static Logger log=LoggerFactory.getLogger(SpringBeanFactory.class);
	
	private static ApplicationContext context;
	
	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		context = applicationContext;
	}
	
	public static <T> T getBean(Class<T> clazz){
		try {
			return context.getBean(clazz);
		} catch (Exception e) {
			log.error("SpringBeanFactory Error", e);
		}
		return null;
	}

}
